<?php
namespace app\models;

use yii\db\ActiveRecord;
use app\models\ShopRecord;

class Shop extends ActiveRecord
{
    public static function tableName(){
         return "{{%shop_null}}";
     }
 
    public function rules(){
         return [
             [['name','image','score'],'required'],
          ];
      }   
 
    public function attributeLabels()
    {  
         return [
           'id' => '商品序号',
           'name' => '商品名',
           'description' => '商品描述',
           'image' => '商品图片',
           'score' => '所需积分',
           'count' => '库存',
           'shop' => '店家名',
           'timeLimit' => '有效期',
           'days' => '上架天数',
           'settime' => '上架时间',
           'soldoutTime' => '下架时间',
           'isShow' => '状态',
          ];
      }

    public function judgeId($id){
       $data = Shop::find()->where('id = :id',[':id' => $id] )->asArray()->one();
       return $data;
    }
     
    public function showUpdate($data){
       $key = [
          'id' => $data['id'],
        ];
       $changedata = [
          'isShow' => $data['isShow'],
        ];
       $result = Shop::updateAll($changedata,$key);
       if( $result != 1){
           $result = -1;
        }else{
           $result = 1;
        }
        return $result;
    }
    
   //库存update
   public function countUpdate($data){
       $key = [
          'id' => $data['id'],
        ];      
       $changedata = [
          'count' => $data['count'],
        ];      
       $result = Shop::updateAll($changedata,$key);
       if( $result != 1){
           $result = -1;
        }else{  
           $result = 1;
        }       
        return $result;
    }

}
